package com.fanh.conf;

import com.fanh.common.wxpay.sdk.IWXPayDomain;
import com.fanh.common.wxpay.sdk.WXPayConfig;
import com.fanh.common.wxpay.sdk.WXPayConstants;
import lombok.Data;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;


@Data
public class MyConfig extends WXPayConfig {

    private byte[] certData;

     private  String certPath;
     private String appID;
     private String mchID;
     private String key;





    public MyConfig(String certPath, String appID, String mchID, String key) throws Exception {

        this.key=key;
        this.mchID=mchID;
        this.appID=appID;
        this.certPath=certPath;

        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }


    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    public IWXPayDomain getWXPayDomain(){
        IWXPayDomain iWXPayDomain =new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iWXPayDomain;
    }




}
